package com.woniuxy.hrp.provider;

import com.woniuxy.hrp.entity.Reservation;
import org.apache.ibatis.jdbc.SQL;

public class ReservationSqlProvider {
    public static String getByCondition(Reservation reservation) {
        String sql = new SQL() {
            {
                SELECT("*");
                FROM("hrp_reservation");
                if (reservation.getId() != null) {
                    WHERE("id=#{id}");
                }
                if (reservation.getPatient()!=null&&reservation.getPatient().getId() != 0) {
                    WHERE("patient_id=#{patient.id}");
                }
                if (reservation.getDoctorAndTime()!=null&&reservation.getDoctorAndTime().getId()!= 0) {
                    WHERE("doctor_time_id=#{doctorTime.id}");
                }
                if (reservation.getPayMentType()!=null&&reservation.getPayMentType().getId()!= 0) {
                    WHERE("PayMentType_id=#{payMentType.id}");
                }
                if (reservation.getStatus()!= null) {
                    WHERE("status=#{status}");
                }

            }
        }.toString();
        return sql;
    }
}
